package gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

import bo.BusinessFigure;
import bo.Company;

/**
 * this class is an application gui based on a JFrame
 * this class wil display all result panels and tables
 * @author Nikolai Straessle
 *
 */
public class ResultGui {

	private JFrame frmResultat;
	private Company aCompany;
	private List<BusinessFigure> aListFigure;
	private ProfitResPanel profitPanel;
	private RevenueResTab revenueTable;
	private RevenueResPanel revenuePanel;
	private ProfitResTab profitTable;
	private JTextArea txtWarning;

	/**
	 * this constructor will create a swing application frame based on a JFrame
	 * this will display all result panels and tables
	 * @param aListFigure
	 * 		java.util.List<BusinessFigure>
	 */
	public ResultGui(List<BusinessFigure> aListFigure) {
		super();
		this.aCompany = Company.getInstance();
		this.aListFigure = aListFigure;
		initialize();
	}



	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmResultat = new JFrame();
		frmResultat.setTitle("Resultat");
		frmResultat.setBounds(100, 100, 893, 1030);
		frmResultat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmResultat.getContentPane().setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 140, 857, 673);
		frmResultat.getContentPane().add(tabbedPane);
		
		JLabel lblFirma = new JLabel("Firma:");
		lblFirma.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblFirma.setBounds(10, 11, 122, 26);
		frmResultat.getContentPane().add(lblFirma);
		
		JLabel lblName = new JLabel("Name:");
		lblName.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblName.setBounds(10, 46, 122, 26);
		frmResultat.getContentPane().add(lblName);
		
		JLabel lblVorname = new JLabel("Vorname:");
		lblVorname.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblVorname.setBounds(10, 83, 122, 26);
		frmResultat.getContentPane().add(lblVorname);
		
		JLabel label = new JLabel(aCompany.getCompanyName());
		label.setFont(new Font("Tahoma", Font.BOLD, 15));
		label.setBounds(142, 11, 279, 26);
		frmResultat.getContentPane().add(label);
		
		JLabel label_1 = new JLabel(aCompany.getName());
		label_1.setFont(new Font("Tahoma", Font.BOLD, 15));
		label_1.setBounds(142, 46, 279, 26);
		frmResultat.getContentPane().add(label_1);
		
		JLabel label_2 = new JLabel(aCompany.getPreName());
		label_2.setFont(new Font("Tahoma", Font.BOLD, 15));
		label_2.setBounds(142, 83, 279, 26);
		frmResultat.getContentPane().add(label_2);
		
		txtWarning = new JTextArea();
		txtWarning.setBackground(Color.RED);
		txtWarning.setForeground(Color.RED);
		txtWarning.setFont(new Font("Segoe UI", Font.BOLD, 15));
		txtWarning.setText("Diese Applikation zeigt nur das Verhalten des Umsatzes und des Gewinns f\u00FCr die n\u00E4chsten Jahre anhand des Regressionsalgorithmus an. In der Realit\u00E4t kann der Umsatz und der Gewinn von den hier errechneten Werten stark abweichen.");
		txtWarning.setEditable(false);
		txtWarning.setEnabled(false);
		txtWarning.setLineWrap(true);
		txtWarning.setWrapStyleWord(true);
		txtWarning.setBounds(10, 824, 857, 136);
		frmResultat.getContentPane().add(txtWarning);
		txtWarning.setColumns(10);
		
		JLabel lblAlleZahlenIn = new JLabel("Alle Zahlen in Schweizer Franken");
		lblAlleZahlenIn.setBounds(20, 108, 241, 26);
		frmResultat.getContentPane().add(lblAlleZahlenIn);
		
		JMenuBar menuBar = new JMenuBar();
		frmResultat.setJMenuBar(menuBar);
		
		JMenu mnStart = new JMenu("Start");
		menuBar.add(mnStart);
		
		JMenuItem mntmNeustart = new JMenuItem("Neustart");
		mntmNeustart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frmResultat.dispose();
				new StartGui();
			}
		});
		mnStart.add(mntmNeustart);
		
		revenuePanel = new RevenueResPanel(aListFigure);
		tabbedPane.addTab("Umsatz", null, revenuePanel, null);
		profitPanel = new ProfitResPanel(aListFigure);
		tabbedPane.addTab("Gewinn", null, profitPanel, null);
		revenueTable = new RevenueResTab(aListFigure);
		JScrollPane revenueSP = new JScrollPane(revenueTable);		
		tabbedPane.addTab("Umsatz Tabellarisch", revenueSP);
		profitTable = new ProfitResTab(aListFigure);
		JScrollPane profitSP = new JScrollPane(profitTable);
		tabbedPane.addTab("Gewinn Tabellarisch", profitSP);
		
		frmResultat.setVisible(true);
	}
}
